package cn.mrcode.smartPluginSecurity.tag;

import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.tags.RoleTag;

import java.util.Arrays;

/**
 * 判断当前用户是否拥有其中所有的角色（逗号分割，表示“与”的关系）
 * @author zhuqiang
 * @version V1.0
 * @date 2015/11/21 15:45
 */
public class HasAllRoles extends RoleTag {
    private static final String ROLE_NAMES_DELIMITER = ",";
    @Override
    protected boolean showTagBody(String roleName) {
        boolean hasAllRole = false;
        Subject subject = getSubject();
        if(subject != null){  //使用当前用户的 subject来获取授权的信息
            hasAllRole = subject.hasAllRoles(Arrays.asList(roleName.split(ROLE_NAMES_DELIMITER)));
        }
        return hasAllRole;
    }
}
